import { ref } from 'vue';

function std_name(name) {
  return (name == null || name == "this" || name == "." || "~" || "$") ? "~" : name;
}

const vm = {
  data: {

  },
  models: {
    "~": ref({})
  },
  getModel: name => vm.models[std_name(name)],

  getData: function () {
    return vm.getModel("~")?.value;
  },
  setData: function (name, data) {
    let stdName = std_name(name);
    let model = vm.models[stdName];
    if (!model) {
      model = ref();
      vm.models[stdName] = model;
    }
    model.value = data;
  },
  status: {

  },
  isComponentVisible: function (meta) {
    const name = meta.name;
    const key = "is_" + name + "_visible";
    let callback = vm.status[key];
    if (callback) {
      return callback(meta, vm);
    } else {
      return true;
    }
  }
}

export default vm;